package com.gouaixin.bee.beeframework2.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ab.util.AbToastUtil;
import com.google.gson.Gson;
import com.gouaixin.bee.beeframework2.MyConfig;
import com.gouaixin.bee.beeframework2.R;
import com.gouaixin.bee.beeframework2.bean.Pay;
import com.gouaixin.bee.beeframework2.model.PayModel;
import com.gouaixin.bee.beeframework2.tool.mLog;


/**
 * Created by Administrator on 2015/3/9.
 */

//最近访客
public class F1_PaySelectActivity extends FragmentActivity {
    Context context = F1_PaySelectActivity.this;

    //顶部
    ImageView back;//返回
    TextView order_name,order_price,problemMore,problemShow;
    LinearLayout paytype_alipay,paytype_weixin,paytype_unionpay,paytype_phonecard;


    LinearLayout qqKefu;//QQ客服
    LinearLayout dianhuaKefu;//电话客服






    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.f1_payselect);

        initView();

        initIntent();

        setListener();

    }

    String name="",price="";
    Pay bean;
    private void initIntent() {
        Intent it=getIntent();
        bean=new Gson().fromJson(it.getStringExtra("pay"),Pay.class);
        mLog.e("确认订单界面接受的pay=" + new Gson().toJson(bean));
        order_name.setText(bean.getTradeName());
        order_price.setText(bean.getAmount());


//        name=it.getStringExtra("name");
//        price=it.getStringExtra("price");
//        order_name.setText(name);
//        order_price.setText(price);
//
//        //封装成pay订单对象
//        bean=new Pay();
//        bean.setAmount(price);
//        bean.setTradeName(name);
//        String cid=PreferencesUtils.getString(context,"cid");
//        bean.setCid(cid);
    }

    private void initView() {
        back = (ImageView) findViewById(R.id.back);

        order_name= (TextView) findViewById(R.id.order_name);
        order_price= (TextView) findViewById(R.id.order_price);
        problemMore= (TextView) findViewById(R.id.problemMore);
        problemShow= (TextView) findViewById(R.id.problemShow);

        paytype_alipay= (LinearLayout) findViewById(R.id.paytype_alipay);
        paytype_weixin= (LinearLayout) findViewById(R.id.paytype_weixin);
        paytype_unionpay= (LinearLayout) findViewById(R.id.paytype_unionpay);
        paytype_phonecard= (LinearLayout) findViewById(R.id.paytype_phonecard);

        qqKefu= (LinearLayout) findViewById(R.id.qqKefu);
        dianhuaKefu= (LinearLayout) findViewById(R.id.dianhuaKefu);

    }

    boolean problemMore_flag=false;//记录当前的点击状态=problemMore
    private void setListener() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        problemMore.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        problemMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(problemMore_flag==true){
                    problemShow.setVisibility(View.GONE);
                    problemMore_flag=false;
                }else{
                    problemShow.setVisibility(View.VISIBLE);
                    problemMore_flag=true;
                }
            }
        });

        paytype_alipay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                AbToastUtil.showToast(context, "您选择的支付方式：" + "支付宝");
                mLog.e("传递给支付宝的pay：" + new Gson().toJson(bean));
                PayModel.initZhifubao(context, bean);
            }
        });

        paytype_weixin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AbToastUtil.showToast(context,"微信支付正在开发中……");

            }
        });

        paytype_unionpay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                AbToastUtil.showToast(context,"您选择的支付方式："+"网银+");//使用它网银+代理
                mLog.e("传递给网银+的pay：" + new Gson().toJson(bean));
                PayModel.initWangying(context, bean);

            }
        });

        paytype_phonecard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                AbToastUtil.showToast(context,"手机充值卡支付正在开发中……");

                mLog.e("传递给神州付的pay：" + new Gson().toJson(bean));
                PayModel.initShenzhou(context, bean);

            }
        });



        qqKefu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(context, "QQ客服" + "功能正在开发中", Toast.LENGTH_SHORT).show();

                String url="mqqwpa://im/chat?chat_type=wpa&uin="+ MyConfig.QQ+"&version=1";//uin改为目标QQ号！

                mLog.e("QQurl=" + url);

                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));//就OK了！！

            }
        });

        dianhuaKefu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context,"电话客服"+"功能正在开发中",Toast.LENGTH_SHORT).show();
                Uri uri = Uri.parse("tel:13419527681");
                Intent it = new Intent(Intent.ACTION_DIAL, uri);

                if (it.resolveActivity(getPackageManager()) != null) {
                    startActivity(it);
                }else{
                    AbToastUtil.showToast(context,"您的手机不支持此功能。请手动添加此QQ:"+MyConfig.QQ);
                }

            }
        });



    }





}
